//
//  FeedbackViewController.m
//  firstpoint
//
//  Created by 泽中 on 2017/7/18.
//  Copyright © 2017年 xzcysoft. All rights reserved.
//

#import "FeedbackViewController.h"

@interface FeedbackViewController ()<UITextViewDelegate>
{
    UITextView *aatextView;
}


@end

@implementation FeedbackViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}
-(void)yijianRequest
{
    
    }
-(void)promptViewmessage:(NSString *)message sureBlock:(void(^)())sureBlock
{
    UIAlertController * alert= [HTTPURL showOneAlertWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert sureTitle:@"确定" sureBlock:^{
        sureBlock();
    }];
    [self presentViewController:alert animated:YES completion:nil];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"意见反馈";
    UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width_screen, height_screen)];
    btn.backgroundColor = [UIColor clearColor];
    [btn addTarget:self action:@selector(onTapBg:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    
    self.view.backgroundColor = COLOR(249, 249, 249, 1);
    [self addView];
    // Do any additional setup after loading the view.
}
-(void)onTapBg:(id)sender{
    [self.view endEditing:YES];
}
-(void)addView{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 75, width_screen, 200)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    
    UILabel *titile = [[UILabel alloc]initWithFrame:CGRectMake(15, 15, 60, 15)];
    titile.textColor = COLOR(68, 68, 68, 1);
    titile.text = @"在线留言";
    titile.font = [UIFont systemFontOfSize:14];
    [view addSubview:titile];
    
    UIView *huiseView = [[UIView alloc]initWithFrame:CGRectMake(15, 39, width_screen-15, 1)];
    huiseView.backgroundColor = COLOR(238, 238, 238, 1);
    [view addSubview:huiseView];
    
    aatextView = [[UITextView alloc]initWithFrame:CGRectMake(15, 45, width_screen-30, 110)];
    aatextView.text = @"请在此输入您遇到的问题";
    aatextView.textColor = [UIColor grayColor];
    aatextView.delegate = self;
    [view addSubview:aatextView];
    
    UIView *ahuiseView = [[UIView alloc]initWithFrame:CGRectMake(15, 160, width_screen-15, 1)];
    ahuiseView.backgroundColor = COLOR(238, 238, 238, 1);
    [view addSubview:ahuiseView];
    
    
    UILabel *titileLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 170, width_screen-60, 15)];
    titileLabel.textColor = COLOR(140, 140, 140, 1);
    titileLabel.font = [UIFont systemFontOfSize:14];
    [view addSubview:titileLabel];
    
    
    NSArray *array = @[@"提交在线留言",@"拨打客服电话"];
    for (int a=0; a<1; a++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame =CGRectMake(15, 295+(51*a), width_screen-30, 36);
        [button setBackgroundColor:COLOR(61, 160, 248, 1)];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        button.layer.masksToBounds = YES;
        button.layer.cornerRadius = 4;
        button.tag=a+100;
        [button setTitle:array[a] forState:UIControlStateNormal];
        [button addTarget: self action:@selector(yijianBtnCilci:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
    }
    
    UILabel *ladlfas = [[UILabel alloc]initWithFrame:CGRectMake(20, 392, width_screen-40, 15)];
    
    ladlfas.textColor = COLOR(140, 140, 140, 1);
    ladlfas.text = @"客服工作时间每天8:30-17:30，仅收取市话费用，免收长途费";
    ladlfas.font = [UIFont systemFontOfSize:12];
        [self.view addSubview:ladlfas];
    
}


-(void)yijianBtnCilci:(UIButton *)btn
{
    if (btn.tag==100) {
        NSString *temp = [aatextView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
        
        
        if ([temp length]==0) {
            [self promptViewmessage:@"输入不能为空" sureBlock:^{
                
            }];
        }else{
            [self yijianRequest];
        }
    }else{
        [self callAction];
    }
}
- (void)callAction{
    NSString *number = @"01082628382";// 此处读入电话号码
    // NSString *num = [[NSString alloc]initWithFormat:@"tel://%@",number]; //number为号码字符串 如果使用这个方法结束电话之后会进入联系人列表
    
    NSString *num = [[NSString alloc]initWithFormat:@"telprompt://%@",number]; //而这个方法则打电话前先弹框 是否打电话 然后打完电话之后回到程序中 网上说这个方法可能不合法 无法通过审核
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]]; //拨号
}
#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if(textView.text.length < 1){
        textView.text = @"请在此输入您遇到的问题";
        textView.textColor = [UIColor grayColor];
    }
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"请在此输入您遇到的问题"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}
@end
